home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / portage / bin / quickpkg < prev    next >
Encoding:
Text File  |  2006-06-30  |  4.2 KB  |  152 lines

  1. #!/bin/bash
  2. # Copyright 1999-2006 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Id: /var/cvsroot/gentoo-src/portage/bin/quickpkg,v 1.13.2.6 2005/08/10 22:08:48 vapier Exp $
  5.  
  6. # This script tries to quickly create a Gentoo binary package using the
  7. # VDB_PATH/category/pkg/*  files
  8. #
  9. # Resulting tbz2 file will be created in ${PKGDIR} ...
  10. # default is /usr/portage/packages/All/
  11.  
  12. if [ "${UID}" != "0" ] ; then
  13.     echo "You must run this as root"
  14.     exit 1
  15. fi
  16.  
  17. export PORTAGE_DB=$(portageq vdb_path)
  18. export ROOT=$(portageq envvar ROOT)
  19. export ROOT=${ROOT%/}/
  20.  
  21. if [ -z "$1" ] || [ $1 == "-h" ] || [ $1 == "--help" ] ; then
  22.     echo "QUICKPKG ver 1.2"
  23.     echo "USAGE: quickpkg <list of pkgs>"
  24.     echo "    a pkg can be of the form:"
  25.     echo "        - ${PORTAGE_DB}/<CATEGORY>/<PKG-VERSION>/"
  26.     echo "        - single depend-type atom ..."
  27.     echo "              if portage can emerge it, quickpkg can make a package"
  28.     echo "              for exact definitions of depend atoms, see ebuild(5)"
  29.     echo
  30.     echo "EXAMPLE:"
  31.     echo "    quickpkg ${PORTAGE_DB}/net-www/apache-1.3.27-r1"
  32.     echo "        package up apache, just version 1.3.27-r1"
  33.     echo "    quickpkg apache"
  34.     echo "        package up apache, all versions of apache installed"
  35.     echo "    quickpkg =apache-1.3.27-r1"
  36.     echo "        package up apache, just version 1.3.27-r1"
  37.     exit 1
  38. fi
  39.  
  40. export PKGDIR=$(portageq envvar PKGDIR)
  41. export PORTAGE_TMPDIR=$(portageq envvar PORTAGE_TMPDIR)
  42.  
  43. source /sbin/functions.sh
  44.  
  45. # here we make a package given a little info
  46. # $1 = package-name w/version
  47. # $2 = category
  48. do_pkg() {
  49.     mkdir -p "${PORTAGE_TMPDIR}/binpkgs" || exit 1
  50.     chmod 0750 "${PORTAGE_TMPDIR}/binpkgs"
  51.     MYDIR="${PORTAGE_TMPDIR}/binpkgs/$1"
  52.     SRCDIR="${PORTAGE_DB}/$2/$1"
  53.     LOG="${PORTAGE_TMPDIR}/binpkgs/$1-quickpkglog"
  54.  
  55.     ebegin "Building package for $1"
  56.     (
  57.         # clean up temp directory
  58.         rm -rf "${MYDIR}"
  59.  
  60.         # get pkg info files
  61.         mkdir -p "${MYDIR}"/temp
  62.         cp "${SRCDIR}"/* "${MYDIR}"/temp/
  63.  
  64.         # create filelist and a basic tbz2
  65.         gawk '{
  66.             if ($1 != "dir") {
  67.                 if ($1 == "obj")
  68.                     NF=NF-2
  69.                 else if ($1 == "sym")
  70.                     NF=NF-3
  71.                 print
  72.             }
  73.         }' "${SRCDIR}"/CONTENTS | cut -f2- -d" " - | sed -e 's:^/:./:' > "${MYDIR}"/filelist
  74.         tar vjcf "${MYDIR}"/bin.tar.bz2 -C "${ROOT}" --files-from="${MYDIR}"/filelist --no-recursion
  75.  
  76.         # join together the basic tbz2 and the pkg info files
  77.         xpak "${MYDIR}"/temp "${MYDIR}"/inf.xpak
  78.         tbz2tool join "${MYDIR}"/bin.tar.bz2 "${MYDIR}"/inf.xpak "${MYDIR}"/$1.tbz2
  79.  
  80.         # move the final binary package to PKGDIR
  81.         [ -d "${PKGDIR}"/All ] ||  mkdir -p "${PKGDIR}"/All
  82.         [ -d "${PKGDIR}/$2" ] || mkdir -p "${PKGDIR}/$2"
  83.         mv "${MYDIR}"/$1.tbz2 "${PKGDIR}"/All
  84.         ( cd "${PKGDIR}/$2" && ln -s ../All/$1.tbz2 )
  85.  
  86.         # cleanup again
  87.         rm -rf "${MYDIR}"
  88.     ) >& "${LOG}"
  89.  
  90.     if [ -e "${PKGDIR}/All/$1.tbz2" ] ; then
  91.         rm -f "${LOG}"
  92.         PKGSTATS="${PKGSTATS}"$'\n'"$(einfo $1: $(du -h "${PKGDIR}/All/$1.tbz2" | gawk '{print $1}'))"
  93.         eend 0
  94.     else
  95.         cat ${LOG}
  96.         PKGSTATS="${PKGSTATS}"$'\n'"$(ewarn $1: not created)"
  97.         eend 1
  98.     fi
  99. }
  100.  
  101. # here we parse the parameters given to use on the cmdline
  102. export PKGERROR=""
  103. export PKGSTATS=""
  104. for x in "$@" ; do
  105.  
  106.     # they gave us full path
  107.     if [ -e "${x}"/CONTENTS ] ; then
  108.         x=$(readlink -f $x)
  109.         pkg=$(echo ${x} | cut -d/ -f6)
  110.         cat=$(echo ${x} | cut -d/ -f5)
  111.         do_pkg "${pkg}" "${cat}"
  112.  
  113.     # lets figure out what they want
  114.     else
  115.         DIRLIST=$(portageq match "${ROOT}" "${x}")
  116.         if [ -z "${DIRLIST}" ] ; then
  117.             eerror "Could not find anything to match '${x}'; skipping"
  118.             export PKGERROR="${PKGERROR} ${x}"
  119.             continue
  120.         fi
  121.  
  122.         for d in ${DIRLIST} ; do
  123.             pkg=$(echo ${d} | cut -d/ -f2)
  124.             cat=$(echo ${d} | cut -d/ -f1)
  125.             if [ -f "${PORTAGE_DB}/${cat}/${pkg}/CONTENTS" ] ; then
  126.                 do_pkg ${pkg} ${cat}
  127.             elif [ -d "${PORTAGE_DB}/${cat}/${pkg}" ] ; then
  128.                 ewarn "Package '${cat}/${pkg}' was injected; skipping"
  129.             else
  130.                 eerror "Unhandled case (${cat}/${pkg}) !"
  131.                 eerror "Please file a bug at http://bugs.gentoo.org/"
  132.                 exit 10
  133.             fi
  134.         done
  135.     fi
  136.  
  137. done
  138.  
  139. if [ -z "${PKGSTATS}" ] ; then
  140.     eerror "No packages found"
  141.     exit 1
  142. else
  143.     echo $'\n'"$(einfo Packages now in ${PKGDIR}:)${PKGSTATS}"
  144. fi
  145. if [ ! -z "${PKGERROR}" ] ; then
  146.     ewarn "The following packages could not be found:"
  147.     ewarn "${PKGERROR}"
  148.     exit 2
  149. fi
  150.  
  151. exit 0
  152.